package com.next.myapplication.slice;

import com.next.androidintentlibrary.*;
import com.next.myapplication.ResourceTable;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.aafwk.content.Operation;
import ohos.agp.components.Component;
import ohos.utils.net.Uri;

public class MainAbilitySlice extends AbilitySlice implements Component.ClickedListener {
    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_main);
        findComponentById(ResourceTable.Id_btn_call_Browser).setClickedListener(this);
        findComponentById(ResourceTable.Id_btn_call_bilibili).setClickedListener(this);
        findComponentById(ResourceTable.Id_btn_call_phoneDial).setClickedListener(this);
        findComponentById(ResourceTable.Id_btn_call_Camera).setClickedListener(this);
        findComponentById(ResourceTable.Id_btn_call_Gallery).setClickedListener(this);
        findComponentById(ResourceTable.Id_btn_call_Contact).setClickedListener(this);
        findComponentById(ResourceTable.Id_btn_call_FileChooser).setClickedListener(this);
        findComponentById(ResourceTable.Id_btn_call_Settings).setClickedListener(this);
        findComponentById(ResourceTable.Id_btn_call_Search).setClickedListener(this);
        findComponentById(ResourceTable.Id_btn_call_APNSettings).setClickedListener(this);
        findComponentById(ResourceTable.Id_btn_call_bluetooth).setClickedListener(this);

    }

    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }

    @Override
    public void onClick(Component component) {

        switch (component.getId()) {
            case ResourceTable.Id_btn_call_Browser:
                BrowserIntents.from(this).openBrowser().show();
                break;
            case ResourceTable.Id_btn_call_bilibili:
                BrowserIntents.from(this).openLink("https://www.bilibili.com").show();
                break;
            case ResourceTable.Id_btn_call_phoneDial:
                PhoneIntents.from(this).showDialNumber("110").show();
                break;
            case ResourceTable.Id_btn_call_Camera:
                CameraIntents.from(this).openVideoCamera().show();
                break;
            case ResourceTable.Id_btn_call_Gallery:
                GalleryIntents.from(this).openGallery().show();
                break;
            case ResourceTable.Id_btn_call_Contact:
                ContactIntents.from(this).openContacts().show();
                break;
            case ResourceTable.Id_btn_call_FileChooser:
                FileIntents.from(this).fileChooser().show();
                break;
            case ResourceTable.Id_btn_call_Settings:
                SettingIntents.from(this).setting().show();
                break;
            case ResourceTable.Id_btn_call_Search:
                SearchIntents.from(this).searchWeb("test").show();
                break;
            case ResourceTable.Id_btn_call_APNSettings:
                SettingIntents.from(this).apnSetting().show();
                break;
            case ResourceTable.Id_btn_call_bluetooth:
                SettingIntents.from(this).bluetoothSetting().show();
                break;

        }
    }

    public void startBrower(){
        Intent intent = new Intent();
        intent.setAction("android.intent.action.VIEW");
        Uri uri = Uri.parse("https://www.bilibili.com");
        intent.setUri(uri);
        startAbility(intent);
    }
}
